package com.ys.service.kefu.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ys.entity.kefu.TkfKnowOpinion;
import com.ys.enume.kefu.TkfKnowOpinionEnum;
import com.ys.mapper.kefu.TkfKnowOpinionMapper;
import com.ys.service.kefu.TkfKnowOpinionService;
import com.ys.util.shiro.ShiroUtils;
import com.ys.vo.R;

@Service("tkfKnowOpinionService")
public class TkfKnowOpinionServiceImpl implements TkfKnowOpinionService {
	
	@Autowired
	private TkfKnowOpinionMapper tkfKnowOpinionMapper;
	
	@Override
	@Transactional
	public R add(Long knowId, String opinion, Integer score) throws Exception {
		
		String createUser = ShiroUtils.getUserId();
		Integer state = TkfKnowOpinionEnum.State.INIT.value;
		TkfKnowOpinion entity = TkfKnowOpinion.tkfKnowOpinion(knowId, score, opinion, createUser, state, 1);
		
		tkfKnowOpinionMapper.insert(entity);
		
		return R.ok();
	}

	@Override
	public R deleteTrue(Long id) throws Exception {
		if (id == null) {
			return R.error("ID不能为空");
		}
		
		tkfKnowOpinionMapper.deleteTrue(id);
		return R.ok();
	}
}
